package org.locker.device.controller.admin;

import java.util.List;

import lombok.RequiredArgsConstructor;
import jakarta.servlet.http.HttpServletResponse;
import jakarta.validation.constraints.*;
import cn.dev33.satoken.annotation.SaCheckPermission;
import org.locker.domain.bo.ManagerConfigBo;
import org.locker.domain.vo.ManagerConfigVo;
import org.locker.service.IManagerConfigService;
import org.springframework.web.bind.annotation.*;
import org.springframework.validation.annotation.Validated;
import org.locker.common.idempotent.annotation.RepeatSubmit;
import org.locker.common.log.annotation.Log;
import org.locker.common.web.core.BaseController;
import org.locker.common.mybatis.core.page.PageQuery;
import org.locker.common.core.domain.R;
import org.locker.common.core.validate.AddGroup;
import org.locker.common.core.validate.EditGroup;
import org.locker.common.log.enums.BusinessType;
import org.locker.common.excel.utils.ExcelUtil;
import org.locker.common.mybatis.core.page.TableDataInfo;

/**
 * 场地分润配置
 *
 * @author winnie
 * @date 2023-11-05
 */
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/device/managerConfig")
public class ManagerConfigController extends BaseController {

    private final IManagerConfigService managerConfigService;

    /**
     * 查询场地分润配置列表
     */
    @SaCheckPermission("device:managerConfig:list")
    @GetMapping("/list")
    public TableDataInfo<ManagerConfigVo> list(ManagerConfigBo bo, PageQuery pageQuery) {
        return managerConfigService.queryPageList(bo, pageQuery);
    }

    /**
     * 导出场地分润配置列表
     */
    @SaCheckPermission("device:managerConfig:export")
    @Log(title = "场地分润配置", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(ManagerConfigBo bo, HttpServletResponse response) {
        List<ManagerConfigVo> list = managerConfigService.queryList(bo);
        ExcelUtil.exportExcel(list, "场地分润配置", ManagerConfigVo.class, response);
    }

    /**
     * 获取场地分润配置详细信息
     *
     * @param managerConfigId 主键
     */
    @SaCheckPermission("device:managerConfig:query")
    @GetMapping("/{managerConfigId}")
    public R<ManagerConfigVo> getInfo(@NotNull(message = "主键不能为空")
                                     @PathVariable Long managerConfigId) {
        return R.ok(managerConfigService.queryById(managerConfigId));
    }

    /**
     * 新增场地分润配置
     */
    @SaCheckPermission("device:managerConfig:add")
    @Log(title = "场地分润配置", businessType = BusinessType.INSERT)
    @RepeatSubmit()
    @PostMapping()
    public R<Void> add(@Validated(AddGroup.class) @RequestBody ManagerConfigBo bo) {
        return toAjax(managerConfigService.insertByBo(bo));
    }

    /**
     * 修改场地分润配置
     */
    @SaCheckPermission("device:managerConfig:edit")
    @Log(title = "场地分润配置", businessType = BusinessType.UPDATE)
    @RepeatSubmit()
    @PutMapping()
    public R<Void> edit(@Validated(EditGroup.class) @RequestBody ManagerConfigBo bo) {
        return toAjax(managerConfigService.updateByBo(bo));
    }

    /**
     * 删除场地分润配置
     *
     * @param managerConfigIds 主键串
     */
    @SaCheckPermission("device:managerConfig:remove")
    @Log(title = "场地分润配置", businessType = BusinessType.DELETE)
    @DeleteMapping("/{managerConfigIds}")
    public R<Void> remove(@NotEmpty(message = "主键不能为空")
                          @PathVariable Long[] managerConfigIds) {
        return toAjax(managerConfigService.deleteWithValidByIds(List.of(managerConfigIds), true));
    }
}
